module.exports = function ($scope, $state, $stateParams,$resource,$modal,$http,$q, toaster) {
    /* 分页
			* ========================================= */
			$scope.maxSize = 5;             //最多显示多少个按钮
			$scope.bigCurrentPage = 1;      //当前页码
			$scope.itemsPerPage = 10         //每页显示几条
			
			$scope.getlist = function () {
				var para = {
					pageNo:$scope.bigCurrentPage, 
					pageSize:$scope.itemsPerPage
				};
				// para = angular.extend($scope.parameters, para);
				$resource('/api/as/goc/reviewConsutAd/findViewConsultByAdaminList', {}, {}).
				save(para,function(res) {
					console.log(para);
					if (res.errcode !== 0) {
						toaster.error({title:"",body:res.errmsg});
						return;
					}
					console.log(res);
					$scope.objs = res.data.results;
					$scope.bigTotalItems = res.data.totalRecord;

					
				})
			};
			
			$scope.getlist(); 

		$scope.search = function () {
        var para = {
            pageNo:$scope.bigCurrentPage, 
            pageSize:$scope.itemsPerPage,
            expert_name:$scope.expert_name,
            mobile:$scope.mobile
        };
        // para = angular.extend($scope.parameters, para);
        $resource('/api/as/goc/reviewConsutAd/findViewConsultByAdaminList', {}, {}).
        save(para,function(res) {
            console.log(para);
            if (res.errcode !== 0) {
                toaster.error({title:"",body:res.errmsg});
                return;
            }
            console.log(para);
            console.log(res);
            $scope.objs = res.data.results;
            $scope.bigTotalItems = res.data.totalRecord;

            
        })
    };
			
			$scope.edit = function(item){
				$scope.item = item;
		        console.log($scope.item);
		         var modalInstance = $modal.open({
		            template: require('../views/updateConsult.html'),
		            controller: 'updateConsult',
		            size: 'lg',
		            resolve: {
		                items: function () {
		                    return $scope.item;
		                },
		            }
		        });
		        modalInstance.result.then(function (showResult) {   
		             $scope.getlist();
		        });

			}

		$scope.shield = function(id){
			if(confirm('确定要公开吗?~~~')){
				$resource('/api/as/goc/reviewConsutAd/updateConsultIsOpen', {}, {}).
				save({'id' : id},function(res) {
					if (res.errcode !== 0) {
						toaster.error({title:"",body:res.errmsg});
						return;
					}
					console.log(res);
					toaster.success({title:"",body:"公开成功"});
					$scope.getlist(); 
				})
			}
			
		}

		$scope.recovery = function(id){
			if(confirm('确定要关闭吗?~~~')){
				$resource('/api/as/goc/reviewConsutAd/updateConsultIsClose', {}, {}).
				save({'id' : id},function(res) {
					if (res.errcode !== 0) {
						toaster.error({title:"",body:res.errmsg});
						return;
					}
					console.log(res);
					toaster.success({title:"",body:"关闭成功"});
					$scope.getlist(); 

				})
			}
		}

		$scope.upup = function(id){
	       	if(confirm('是否处理此条咨询')){
				$resource('/api/as/goc/reviewConsutAd/updateConsultStateOne', {}, {}).
				save({'id' : id},function(res) {
					if (res.errcode !== 0) {
						toaster.error({title:"",body:res.errmsg});
						return;
					}
					console.log(res);
					toaster.success({title:"",body:"受理成功"});
					$scope.getlist(); 
				})
			}
			
		}
	
		$scope.upups = function(id){
	       	if(confirm('是否处理此条咨询')){
				$resource('/api/as/goc/reviewConsutAd/updateConsultStateTwo', {}, {}).
				save({'id' : id},function(res) {
					if (res.errcode !== 0) {
						toaster.error({title:"",body:res.errmsg});
						return;
					}
					console.log(res);
					toaster.success({title:"",body:"处理完成"});
					$scope.getlist(); 
				})
			}
			
		}
	
		 //页面需要的信息。
			$scope.page = {};
            $scope.info = {
                'aaa' : ''
            }

			var beforedata = {
				//项目类别列表
				'typearr':
				$http({
					'method': 'GET',
					'url': '/api/as/goc/reviewCityResponsible/findAllProjectTypeList',
					// 'params': { 'type': 'sale_category' },
				}),
				//申报单位
				'companyarr':
				$http({
					'method': 'GET',
					'url': 'api/as/goc/reviewCityResponsible/findAllCompanyList',
					// 'params': { 'type': 'ticket_sale_belong' },
				}),
				//项目名称
				'projectarr':
				$http({
					'method': 'GET',
					'url': '/api/as/goc/reviewCityResponsible/findAllProjectList',
				}),
			};

			$q.all(beforedata).then(function (res) {

				//项目类别列表
				if (res.typearr.data.errcode === 0) {
				} else {
					alert('/api/as/goc/reviewCityResponsible/findAllProjectTypeList' + res.typearr.data.errmsg);
					return;
				}
				//申报单位
				if (res.companyarr.data.errcode === 0) {
				} else {
					alert('api/as/goc/reviewCityResponsible/findAllCompanyList' + res.companyarr.data.errmsg);
					return;
				}
				//项目名称
				if (res.projectarr.data.errcode === 0) {
				} else {
					alert('/api/as/goc/reviewCityResponsible/findAllProjectList' + res.projectarr.data.errmsg);
					return;
				}

				$scope.page = {
					//项目类别列表
					'typearr': res.typearr.data.data,
					//申报单位
					'companyarr': res.companyarr.data.data,
					//项目名称
					'projectarr': res.projectarr.data.data,
					// 年度
					'yeararr' : [{'value' : '0', 'label' : '2017'}],
					// 区县/处室
					'areaarr' : [{'value' : '0', 'label' : '处室'},{'value' : '1', 'label' : '区县'}],
				};
				console.log($scope.page);
			});



			


};
